package com.txunda.zhuohired.aty.user.my;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.ants.theantsgo.util.JSONUtils;
import com.ants.theantsgo.util.L;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.base.BaseAty;
import com.txunda.zhuohired.http.pst.InfoPst;

import java.util.Map;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/9 9:17
 * 功能描述：设置家的位置
 * 联系方式：jiahuanchen@126.com
 */

public class HomeLocationAty extends BaseAty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_white_center)
    private TextView tv_layout_white_center;
    /**
     * 地址
     */
    @ViewInject(R.id.tv_home_location_address)
    private TextView tv_home_location_address;

    private int REQUESTCODE = 1;
    private InfoPst infoPst;
    private String token = "";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_white_head);
        tv_layout_white_center.setText("设置家的位置");
    }

    @Override
    @OnClick({R.id.tv_home_location_select})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_home_location_select://地图选点
                startActivityForResult(LocationSelectAty.class, null, REQUESTCODE);
                break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_home_location;
    }

    @Override
    protected void initialized() {
        token = application.getUserInfo().get("data");
        infoPst = new InfoPst(this);
    }

    @Override
    protected void requestData() {
        infoPst.homeAddress(token);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (RESULT_OK == resultCode) {
            if (requestCode == REQUESTCODE) {//设置家的位置
                L.e("========", "测试");

            }
        }
    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if (requestUrl.contains("homeAddress")) {
            //            L.e("==========homeAddress==========", jsonStr);
            Map<String, String> map = JSONUtils.parseKeyAndValueToMap(jsonStr);
            Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
            tv_home_location_address.setText(data.get("home_address"));
            return;
        }
    }
}
